package com.panda.qqclient.view;

import com.panda.qqclient.services.MessageClientService;
import com.panda.qqclient.services.UserClientService;
import com.panda.qqclient.utils.Utility;

import java.io.IOException;

public class QQView {
    public static void main(String[] args) throws IOException {
            new QQView().mainMenu();
    }


    private boolean loop=true;//是否显示菜单
    private boolean loop2=true;
    private String key;
    private UserClientService  userClientService=new UserClientService();


    private void mainMenu() throws IOException {
        while (loop){
            System.out.println("============欢迎登录QQ============");
            System.out.println("\t\t1. 登录系统");
            System.out.println("\t\t9. 退出系统");
            System.out.println("=================================");
            System.out.print("请输入你的选项：");
            key= Utility.readString(1);

            String user=" ";
            String password=" ";
            boolean isExist=true;
            switch (key){
                case "1":
                    System.out.print("请输入账号:");
                    user=Utility.readString(10);
                    System.out.print("请输入密码：");
                    password=Utility.readString(10);

                    if(userClientService.login(user,password)){
                        System.out.println("==============欢迎 "+user+" 登录==============");

                        while (loop2){
                            System.out.println("===========二级菜单==========");
                            System.out.println("1. 显示在线用户列表");
                            System.out.println("2. 群发消息");
                            System.out.println("3. 私聊消息");
                            System.out.println("4. 发送文件");
                            System.out.println("5. 退出系统");
                            System.out.println("============================");

                            System.out.print("请输入你的选项：");
                            key=Utility.readString(1);
                            switch (key){
                                case "1":
                                    System.out.println("在线的用户有：");
                                    userClientService.onlineFriendList();

                                    break;
                                case "2":
                                    System.out.println("please input the words you want to talk to friends");
                                    String content=Utility.readString(100);
                                    new MessageClientService().sendMessageToAll(content,user);
                                    break;
                                case "3":
                                    System.out.println("你想要发给谁");
                                    String getterId = Utility.readString(10);
                                    System.out.println("内容是：");
                                    String content1 = Utility.readString(10);
                                    new MessageClientService().sendMessageToOne(content1,user,getterId);
                                        break;
                                case "4":
                                    System.out.println("no usage");
                                    break;
                                case "5":
                                    loop2=false;
                                    break;
                                default:
                                    System.out.println("输入有误");
                                    break;
                            }
                        }
                    }else{
                        System.out.println("账号或密码有误");
                        System.out.println("=======================");
                    }

                    break;
                case "9":
                    //给服务器发消息，退出线程。
                    System.exit(0);
                    loop=false;
                    break;

            }


        }
    }
}
